package com.r2coding.music.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.r2coding.music.vo.req.QueryMvListReqVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.r2coding.common.util.PageUtils;
import com.r2coding.common.util.Query;

import com.r2coding.music.dao.MvDao;
import com.r2coding.music.entity.MvEntity;
import com.r2coding.music.service.MvService;

/**
 * mv
 *
 * @author 98k灬
 * @email hk666zx@163.com
 * @date 2022-05-04 20:46:11
 */
@Service("mvService")
public class MvServiceImpl extends ServiceImpl<MvDao, MvEntity> implements MvService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MvEntity> page = this.page(
                new Query<MvEntity>().getPage(params),
                new QueryWrapper<MvEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public PageInfo<MvEntity> selectList(QueryMvListReqVo vo) {
        PageHelper.startPage(vo.getCurrent(), vo.getSize());
        QueryWrapper<MvEntity> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(vo.getMvName())) {
            wrapper.like("mv_name", vo.getMvName());
        }
        if (vo.getStatus() > 0) {
            wrapper.eq("status", vo.getStatus());
        }
        if (vo.getRegionId() > 0) {
            wrapper.eq("region_id", vo.getRegionId());
        }
        if (vo.getTypeId() > 0) {
            wrapper.eq("type_id", vo.getTypeId());
        }
        wrapper.orderByDesc("create_time");
        List<MvEntity> list = this.baseMapper.selectList(wrapper);
        return new PageInfo<MvEntity>(list);
    }

    @Override
    public List<MvEntity> getRecommend() {
        PageHelper.startPage(1, 5);
        QueryWrapper<MvEntity> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("play_times");
        List<MvEntity> mvEntities = this.baseMapper.selectList(wrapper);
        return mvEntities;
    }


}